﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Web.Model;
using Portal.Web.Utility;
using Portal.Exam.Bussiness;
using Portal.Core;

namespace Portal.Exam.Render
{
    public class AddGroupQuestion 
    {
        public static AjaxOut Draw(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                string BackUrl = "GroupQuestion.aspx";
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                string AccountType = WebEnvironments.Request(SiteId, "AccountType");
                if (string.IsNullOrEmpty(AccountType)) AccountType = "";

                string RetHtml =
                    "<input type=hidden id=txtAccountType value=\"" + AccountType + "\">\r\n" +
                    "<script language=\"javascript\">\r\n" +
                    //"   function ClientSaveAddExamPersonal(WhoIsExamId)\r\n" +
                    //"    {\r\n" +
                    //"       SiteId='" + SiteId + "';\r\n" +
                    //"        AccountType=document.getElementById(\"txtAccountType\").value;\r\n" +
                    //"        GroupQuestionName=document.getElementById(\"txtGroupQuestionName\").value;\r\n" +
                    //"        RetValue = Portal.Exam.Render.AddExamPersonal.ServerSideAddExamPersonal(SiteId, AccountType, GroupQuestionId, GroupQuestionName).value;\r\n" +
                    //"        if(RetValue.indexOf(\"ERROR\")!=-1)\r\n" +
                    //"        {\r\n" +
                    //"            alert(RetValue);\r\n" +
                    //"            return;\r\n" +
                    //"        }\r\n" +
                    //"        window.open('" + BackUrl + "','_self');\r\n" +
                    //"    }\r\n" +



                    " function ClientSaveAddGroupQuestion()\r\n" +
                    " {\r\n" +
                    "    SiteId='" + SiteId + "';\r\n" +
                    "     AccountType=document.getElementById(\"txtAccountType\").value;\r\n" +
                    "     GroupQuestionName=document.getElementById(\"txtGroupQuestionName\").value;\r\n" +
                    "     SortIndex=document.getElementById(\"txtSortIndex\").value;\r\n" +
                    "     RetValue = Portal.Exam.Render.AddGroupQuestion.ServerSideAddGroupQuestion(SiteId, AccountType, GroupQuestionName, SortIndex ).value;\r\n" +
                    "     if(RetValue.indexOf(\"ERROR\")!=-1)\r\n" +
                    "     {\r\n" +
                    "         alert(RetValue);\r\n" +
                    "         return;\r\n" +
                    "     }\r\n" +
                    "     alert(RetValue);\r\n" +
                    "     window.open('" + BackUrl + "','_self');\r\n" +
                    " }\r\n" +



                    "</script>\r\n" +


                    " <div class=DatabaseFunction>\r\n" +
                    "        <ul>\r\n" +
                    "            <li onclick=\"javascript:ClientSaveAddGroupQuestion();\"><img class=image src=\""+IconRoot+"/Save.png\"><div>Ghi lại</div></li>\r\n" +
                    "            <li onclick=\"javascript:window.open('" + BackUrl + "','_self');\"><img class=image src=\""+IconRoot+"/back.png\"><div>Quay lại</div></li>\r\n" +
                    "        </ul>\r\n" +
                    "  </div>\r\n" +

                    "     <h3>Thông tin chung</h3>" +
                    "     <div class=CssFormSaveUpdate>\r\n" +
                    "     <table>" +
                    "          <tr>" +
                    "              <td class=\"Col1\">Nhóm câu hỏi:</td>" +
                    "              <td><input id=txtGroupQuestionName class=textbox type=textbox></td>" +
                    "          </tr>" +
                    "          <tr>" +
                    "              <td class=\"Col1\">Thứ tự:</td>" +
                    "              <td><input id=txtSortIndex class=textbox type=textbox value=\"1\"></td>" +
                    "          </tr>" +

                    //"          <tr>" +
                    //"              <td></td>" +
                    //"              <td><input type=button class=button  onclick=\"javascript:ClientSaveAddGroupQuestion();\" value=\"Ghi lại\"><input type=button  class=button onclick=\"javascript:window.open('" + BackUrl + "','_self');\" value=\"Thoát\"></td>" +
                    //"          </tr>" +
                    "      </table>\r\n" +
                    " </div>\r\n";
                    
                OAjaxOut.HtmlContent = RetHtml;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.InfoMessage = ex.Message.ToString();
            }
            return OAjaxOut;
        }
        [AjaxPro.AjaxMethod]
        public string ServerSideAddGroupQuestion(
            string SiteId,
            string AccountType,
            string GroupQuestionName,
            string SortIndex)
        {
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                
                if (GroupQuestionName.Trim().Length == 0) throw new Exception("Nhập tên nhóm câu hỏi");

                GroupQuestionBll.AddGroupQuestion(SiteId, AccountType, GroupQuestionName, "", null, null, SortIndex);
                return "Thêm mới nhóm ngân hàng câu hỏi thành công!";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string GetConfirmDeleteMsg(string SiteId)
        {
            return "Bạn đã chắc chắn xóa chưa?";
        }

    }
}